#include <pthread.h>
#include <iostream>
#include <string>
#include <unistd.h>
void *StartRoutine(void *arg)
{
    std::string name = (char *)arg;
    int cnt = 5;
    while (cnt)
    {
        std::cout << name << " is running: " << cnt << ", pid is "
                  << getpid() << ", tid is " << pthread_self() << std::endl;
        sleep(1);
        cnt--;
    }
   // pthread_exit((void*)112);
     return (void*)111;
}

int main()
{
    
    pthread_t tid;
    pthread_create(&tid, nullptr, StartRoutine, (void *)"thread-1");
    sleep(2);
   // pthread_cancel(tid);
    // int cnt = 5;
    // while (cnt)
    // {
    //     std::cout << "main thread is runnning, pid is "
    //               << getpid() << "tid is " << pthread_self() << std::endl;
    //     sleep(1);
    //     cnt--;
    // }
    // void* retval;
    // int n = pthread_join(tid, &retval);
    // if (n == 0)
    //     std::cout << "main thread get a retval: " << (long long)retval << std::endl;
    // sleep(3);
    return 0;
}